<?php
/**
 * Created by PhpStorm.
 * User: coolinmind
 * Date: 21/01/2019
 * Time: 14:27
 */

namespace App\Services\UCenter;


use App\Services\UCenter\UCenter\CarLogic;

class Car
{
    /**
     * 添加车辆
     * @param $data
     * @return array
     * @throws \App\Exceptions\RequestFailException
     */
    public function addCars($data)
    {
        $data = pick_array($data, [
            'plate_type',
            'number',
            'driving_license',
            'car_type',
            'car_length',
            'weight',
            'carriage_num',
            'volume',
            'carrage_length',
            'register_date',
            'car_brand',
            'identification_code',
            'engine',
            'engine_num',
            'car_axle',
            'axle',
            'owner',
            'is_allow',
            'user_id',
//            'certificate'
        ]);
        ValidateCar::checkValidate($data, [
            'plate_type',
            'number',
            'driving_license',
            'car_type',
            'car_length',
            'weight',
            'carriage_num',
            'volume',
            'carrage_length',
            'register_date',
            'car_brand',
            'identification_code',
            'engine',
            'engine_num',
            'axle',
            'car_axle',
            'owner',
            'is_allow',
            'user_id',
//            'certificate'
        ]);
        return (new CarLogic())->addCars($data);
    }

    public function changeCarInfo($data)
    {
        $data = pick_array($data, [
            'id',
            'plate_type',
            'number',
            'driving_license',
            'car_type',
            'car_length',
            'weight',
            'carriage_num',
            'volume',
            'carrage_length',
            'register_date',
            'car_brand',
            'identification_code',
            'engine',
            'engine_num',
            'axle',
            'car_axle',
            'owner',
            'is_allow',
            'user_id'
        ]);
        ValidateCar::checkValidate($data, [
            'id',
            'plate_type',
            'number',
            'driving_license',
            'car_type',
            'car_length',
            'weight',
            'carriage_num',
            'volume',
            'carrage_length',
            'register_date',
            'identification_code',
            'engine_num',
            'axle',
            'car_axle',
            'owner',
            'is_allow',
            'user_id'
        ]);
        return (new CarLogic())->changeCarInfo($data);
    }

    /**
     * 获取车辆列表
     * @param $data
     * @return array
     * @throws \App\Exceptions\RequestFailException
     */
    public function getCarList($data)
    {
        $data = pick_array($data, ['page', 'user_id', 'number', 'car_length', 'weight', 'plate_type', 'is_busy']);
        ValidateCar::checkValidate($data, ['page', 'user_id']);
        return (new CarLogic())->getCarList($data);
    }

    /**
     * 根据id删除车辆信息
     * @param $data
     * @return mixed
     * @throws \App\Exceptions\RequestFailException
     */
    public function delCarById($data)
    {
        $data = pick_array($data, ['user_id', 'id']);
        ValidateCar::checkValidate($data, ['user_id', 'id']);
        return (new CarLogic())->delCarById($data);
    }

    /**
     * 根据id获取车辆详情
     * @param $data
     * @return array
     * @throws \App\Exceptions\RequestFailException
     */
    public function getCarById($data)
    {
        $data = pick_array($data, ['id', 'user_id']);
        ValidateCar::checkValidate($data, ['id', 'user_id']);
        return (new CarLogic())->getCarById($data);
    }

    /**
     * 管理员获取车辆列表
     */
    public function backCarList($data)
    {
        $data = init_array($data, ['keywords']);
        return (new CarLogic())->backCarList($data);
    }

    /**
     * 管理员获取车辆详情
     */
    public function backCarInfo($data)
    {
        $data = init_array($data, ['id']);
        return (new CarLogic())->backCarInfo($data);
    }

    /**
     * 管理员审核车辆
     */
    public function backCarAudit($data)
    {
        $data = init_array($data, ['id', 'status']);
        return (new CarLogic())->backCarAudit($data);
    }
}
